//
//  DXWHomePageViewController.m
//  pandaTV
//
//  Created by 淡馨慰 on 16/9/20.
//  Copyright © 2016年 淡馨慰. All rights reserved.
//

#import "DXWHomePageViewController.h"
#import "DXWHomePageItem.h"
#import "DXWHomePagePictureItem.h"
#import <MJExtension/MJExtension.h>

@interface DXWHomePageViewController ()

/** 直播房间模型数组 */
@property (nonatomic, strong) NSMutableArray *datas;
/** 连播图片模型数组 */
@property (nonatomic, strong) NSMutableArray *pictures;

@end

@implementation DXWHomePageViewController

- (NSMutableArray *)pictures
{
    if (_pictures == nil) {
        _pictures = [NSMutableArray array];
    }
    return _pictures;
}
- (NSMutableArray *)datas
{
    if (_datas == nil) {
        _datas = [NSMutableArray array];
    }
    return _datas;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.titleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"title_image"]];
    self.view.backgroundColor = [UIColor yellowColor];
    
    [self loadData_ScrollPicture];
}

#pragma mark -加载网络数据
- (void)loadData_Room
{
    /*

     
  房间   http://api.m.panda.tv/ajax_get_live_list_by_multicate?pagenum=4&hotroom=1&__version=2.0.1.1339&__plat=ios&__channel=appstore
     
     
  连播图片 http://api.m.panda.tv/ajax_rmd_ads_get?__version=2.0.1.1339&__plat=ios&__channel=appstore
     
  添加频道 http://api.m.panda.tv/ajax_get_all_subcate?__version=2.0.2.1350&__plat=ios&__channel=appstore
     
     */
    AFHTTPSessionManager *manager = [AFHTTPSessionManager dxw_HTTPManager];
    NSDictionary *dict = @{
                           @"pagenum" : @"4",
                           @"hotroom" : @"1",
                           @"__version" : @"2.0.1.1339",
                           @"__plat" : @"ios",
                           @"__channel" : @"appstore"
                           };
    [manager GET:@"http://api.m.panda.tv/ajax_get_live_list_by_multicate?" parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        self.pictures = [DXWHomePageItem  mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
        
//        NSLog(@"%@",responseObject);
//        NSLog(@"%@",_datas);
        DXWHomePageItem *item = _datas[0];
        NSLog(@"%@",item.items);
        //处理缺口
//        [_collectionView reloadData];
        
        
//                [responseObject writeToFile:@"/Users/milkteacat/Desktop/熊猫TV/首页1.plist" atomically:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    
}
- (void)loadData_ScrollPicture
{
    /*
     
     
     房间   http://api.m.panda.tv/ajax_get_live_list_by_multicate?pagenum=4&hotroom=1&__version=2.0.1.1339&__plat=ios&__channel=appstore
     
     
     连播图片 http://api.m.panda.tv/ajax_rmd_ads_get?__version=2.0.1.1339&__plat=ios&__channel=appstore
     */
    AFHTTPSessionManager *manager = [AFHTTPSessionManager dxw_HTTPManager];
    NSDictionary *dict = @{
                           @"__version" : @"2.0.1.1339",
                           @"__plat" : @"ios",
                           @"__channel" : @"appstore"
                           };
    [manager GET:@"http://api.m.panda.tv/ajax_rmd_ads_get?" parameters:dict progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
 
        
        self.pictures = [DXWHomePagePictureItem  mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
        
        //        NSLog(@"%@",responseObject);
        NSLog(@"%@",_pictures);
        DXWHomePagePictureItem *item = _pictures[0];
        NSLog(@"%@",item.url);
        //处理缺口
        //        [_collectionView reloadData];
        
        
                        [responseObject writeToFile:@"/Users/milkteacat/Desktop/熊猫TV/首页2.plist" atomically:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@",error);
    }];
    
}


@end
